package sanphone.com.runningschool.MyOrder;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.MenuItem;
import android.widget.TextView;

import sanphone.com.runningschool.BaseActivity;
import sanphone.com.runningschool.ForceOffline;
import sanphone.com.runningschool.R;

public class AcceptedOrderActivity extends BaseActivity {

    private Toolbar toolbar;
    private TextView accept_name;
    private TextView accept_order_content;
    private TextView accept_order_status;
    private  String status;
    private SharedPreferences sprf;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_accepted_order);
        sprf=getSharedPreferences("data",MODE_PRIVATE);
        ForceOffline offline=new ForceOffline(sprf.getString("schoolId",null),this);
        offline.check();
        initView();

    }

    private void initView() {
        toolbar =  findViewById(R.id.toolbar);
        toolbar.setTitle("");
        setSupportActionBar(toolbar);
        ActionBar actionBar = getSupportActionBar();
        if (actionBar != null) {
            actionBar.setDisplayHomeAsUpEnabled(true);
        }
        accept_name =  findViewById(R.id.accept_name);
        accept_order_content =  findViewById(R.id.accept_order_content);
        accept_order_status =  findViewById(R.id.accept_order_status);
        Intent intent = getIntent();
       accept_name.setText(sprf.getString("nickName",null));
        accept_order_content.setText("物品名称：" + intent.getStringExtra("thingName")
                +"\n物品的说明："+intent.getStringExtra("detail")
                + "\n物品重量：" + intent.getDoubleExtra("thingWeight",0.0)+"kg"
                + "\n起始时间：" + intent.getStringExtra("thingTime")
                + "\n送达时间：" + intent.getStringExtra("deliverTime")
                + "\n起始地址：" + intent.getStringExtra("thingPlace")
                + "\n送达地址：" + intent.getStringExtra("deliverPlace")
                + "\n酬劳：" + intent.getIntExtra("money",0)+"元"
                + "\n发布者：" + intent.getStringExtra("publisherName")
                + "\n联系方式："+intent.getStringExtra("publisherPhone"));
        status = intent.getStringExtra("status");
        Log.e("orderStatus", status );
        if(status.equals("CLOSE")){
            accept_order_status.setText("已完成");
        }else {
            accept_order_status.setText("未完成");
        }
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()){
            case android.R.id.home:
                AcceptedOrderActivity.this.finish();
                break;
        }
        return true;
    }
}
